package com.xcdh.trading.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xcdh.trading.entity.SectorCapitalFlow;
import com.xcdh.trading.mapper.SectorCapitalFlowMapper;
import com.xcdh.trading.response.TradingRes;
import com.xcdh.trading.service.SectorCapitalFlowService;
import com.xcdh.trading.util.TuShareApi;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 板块资金流向服务实现类，继承 ServiceImpl 实现具体业务逻辑
 */
@Service
public class SectorCapitalFlowServiceImpl extends ServiceImpl<SectorCapitalFlowMapper, SectorCapitalFlow> implements SectorCapitalFlowService {
    @Override
    public void syncSectorCapitalFlow(String tradeDate) {
        TradingRes tradingRes = TuShareApi.post("moneyflow_ind_dc", tradeDate);
        List<SectorCapitalFlow> flowList = tradingRes.parse(SectorCapitalFlow.class);
        for (SectorCapitalFlow capitalFlow : flowList) {
            SectorCapitalFlow capitalFlow1 = lambdaQuery()
                    .eq(SectorCapitalFlow::getTsCode, capitalFlow.getTsCode())
                    .eq(SectorCapitalFlow::getTradeDate, capitalFlow.getTradeDate()).one();
            if(capitalFlow1 == null){
                save(capitalFlow) ;
            }
        }
    }
    // 可在此实现自定义业务逻辑方法
}
